USE [GESTION_MORA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_D0007_CREACION_TABLAS]    Script Date: 11/23/2011 14:38:40 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WASP_D0007_CREACION_TABLAS]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[WASP_D0007_CREACION_TABLAS]
GO

USE [GESTION_MORA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_D0007_CREACION_TABLAS]    Script Date: 11/23/2011 14:38:40 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[WASP_D0007_CREACION_TABLAS]
AS

---- creacion de tablas del proceso gestion mora
---- creacion de tablas del proceso gestion mora
BEGIN
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMTMP]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMTMP]
 
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMTME]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMTME]
 
--------------------------------
 
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMSucursales]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMSucursales]
------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMSmoraSuc]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMSmoraSuc]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMSmoraEmpr]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMSmoraEmpr]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMSmora]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMSmora]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMMP]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMMP]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMMora]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMMora]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMMM60]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMMM60]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMME]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMME]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMFallecidos]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMFallecidos]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMEmpresas]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMEmpresas]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMDR]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMDR]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMDP]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMDP]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMDETAFIL]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMDETAFIL]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMDETADESAFIL]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMDETADESAFIL]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMCuentas]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMCuentas]
 
------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMComercialDesafil]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMComercialDesafil]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMComercialAfil]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMComercialAfil]

------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GMBASEGESTCOMER]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[GMBASEGESTCOMER]

------------------------------
 
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Results]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
truncate table [dbo].[Results]

-------
END
 
if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMTMP]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMTMP] (
 [Z073B1Emp] [smallint] NOT NULL ,
 [Z073B1Cta] [int] NOT NULL ,
 [Z073B3Mod] [smallint] NOT NULL ,
 [Z073B3Suc] [smallint] NOT NULL ,
 [Z073B3Mda] [smallint] NOT NULL ,
 [Z073B3Pap] [smallint] NOT NULL ,
 [Z073B3Cta] [int] NOT NULL ,
 [Z073B3Oper] [int] NOT NULL ,
 [Z073B3Sbop] [smallint] NOT NULL ,
 [Z073B3Tope] [smallint] NOT NULL ,
 [Z073B3Fpag] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Z073B3Tipo] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
 [Z073B3Rub] [decimal](16, 0) NULL ,
 [Z073B3Stat] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Z073B3FSt] [datetime] NULL ,
 [Z073B3EExt] [smallint] NULL ,
 [Z073B3Cno] [numeric](18, 0) NULL ,
 [Z073B3CRe] [decimal](17, 2) NULL ,
 [Z073B3Cas] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [NombreDeudor] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
end

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMTME]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMTME] (
 [Z073B1Emp] [smallint] NOT NULL ,
 [Z073B1Cta] [int] NOT NULL ,
 [Z073B3Mod] [smallint] NOT NULL ,
 [Z073B3Suc] [smallint] NOT NULL ,
 [Z073B3Mda] [smallint] NOT NULL ,
 [Z073B3Pap] [smallint] NOT NULL ,
 [Z073B3Cta] [int] NOT NULL ,
 [Z073B3Oper] [int] NOT NULL ,
 [Z073B3Sbop] [smallint] NOT NULL ,
 [Z073B3Tope] [smallint] NOT NULL ,
 [Z073B3Fpag] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Z073B3Tipo] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
 [Z073B3Rub] [decimal](16, 0) NULL ,
 [Z073B3Stat] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Z073B3FSt] [datetime] NULL ,
 [Z073B3EExt] [smallint] NULL ,
 [Z073B3Cno] [numeric](18, 0) NULL ,
 [Z073B3CRe] [decimal](17, 2) NULL ,
 [Z073B3Cas] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [NombreDeudor] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
end

 
if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMSucursales]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMSucursales] (
 [SucOper] [smallint] NOT NULL ,
 [Agencia] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
end

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMSmoraSuc]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMSmoraSuc] (
 [Cuenta_Empresa] [int] NULL ,
 [Nombre_Empresa] [char] (70) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Estado_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Condicion_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Clasificacion_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [SucOper] [smallint] NULL ,
 [Agencia] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta] [int] NULL ,
 [Operacion] [int] NULL ,
 [Nombre_Deudor] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta_Aval1] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval1] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta_Aval2] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval2] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [MM60] [numeric](18, 0) NULL ,
 [DP] [numeric](18, 0) NULL ,
 [DR] [numeric](18, 0) NULL ,
 [Fallecidos] [int] NULL ,
 [Judiciales] [int] NULL ,
 [ME] [int] NULL ,
 [MP] [int] NULL ,
 [MEMP] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Clasificacion_Actual] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Clasificacion_Anterior] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Vcto_Impago] [datetime] NULL ,
 [Valor_Cuota] [numeric](18, 0) NULL ,
 [Mca_securitizado] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
end

 
if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMSmoraEmpr]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMSmoraEmpr] (
 [Cuenta_Empresa] [int] NULL ,
 [Nombre_Empresa] [char] (70) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Estado_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Condicion_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Clasificacion_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [SucOper] [smallint] NULL ,
 [Cuenta] [int] NOT NULL ,
 [Operacion] [int] NOT NULL ,
 [Nombre_Deudor] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta_Aval1] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval1] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta_Aval2] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval2] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [MM60] [numeric](18, 0) NULL ,
 [DP] [numeric](18, 0) NULL ,
 [DR] [numeric](18, 0) NULL ,
 [Fallecidos] [int] NULL ,
 [Judiciales] [int] NULL ,
 [ME] [int] NULL ,
 [MP] [int] NULL ,
 [Vcto_Impago] [datetime] NULL ,
 [Valor_Cuota] [decimal](38, 2) NULL 
) ON [PRIMARY]
end

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMSmora]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMSmora] (
 [Cuenta] [int] NOT NULL ,
 [Operacion] [int] NOT NULL ,
 [Nombre_Deudor] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta_Aval1] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval1] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta_Aval2] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval2] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [MM60] [numeric](18, 0) NULL ,
 [DP] [numeric](18, 0) NULL ,
 [DR] [numeric](18, 0) NULL ,
 [FALLECIDOS] [int] NULL ,
 [JUDICIALES] [int] NULL ,
 [ME] [int] NULL ,
 [MP] [int] NULL ,
 [Vcto_Impago] [datetime] NULL ,
 [Valor_Cuota] [decimal](38, 2) NULL ,
 [Cuenta_Empresa] [int] NULL 
) ON [PRIMARY]
end

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMMP]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMMP] (
 [Z073B3Cta] [int] NOT NULL ,
 [Z073B3Oper] [int] NOT NULL 
) ON [PRIMARY]
end

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMMora]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMMora] (
 [Z073B1Emp] [smallint] NOT NULL ,
 [Z073B1Cta] [int] NOT NULL ,
 [Z073B3Mod] [smallint] NOT NULL ,
 [Z073B3Suc] [smallint] NOT NULL ,
 [Z073B3Mda] [smallint] NOT NULL ,
 [Z073B3Pap] [smallint] NOT NULL ,
 [Z073B3Cta] [int] NOT NULL ,
 [Z073B3Oper] [int] NOT NULL ,
 [Z073B3Sbop] [smallint] NOT NULL ,
 [Z073B3Tope] [smallint] NOT NULL ,
 [Z073B3Fpag] [datetime] NOT NULL ,
 [Z073B3Tipo] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
 [Z073B3Rub] [decimal](16, 0) NULL ,
 [Z073B3Stat] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Z073B3FSt] [datetime] NULL ,
 [Z073B3EExt] [smallint] NULL ,
 [Z073B3CNo] [decimal](17, 2) NULL ,
 [Z073B3CRe] [decimal](17, 2) NULL ,
 [Z073B3Cas] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [CTNOM] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
end

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMMM60]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMMM60] (
 [cuenta] [int] NOT NULL ,
 [operacion] [int] NOT NULL ,
 [Total] [numeric](18, 0) NULL 
) ON [PRIMARY]
end

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMME]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMME] (
 [Z073B3Cta] [int] NOT NULL ,
 [Z073B3Oper] [int] NOT NULL 
) ON [PRIMARY]
end

 

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMFallecidos]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMFallecidos] (
 [Cuenta] [int] NULL ,
 [Fech_Fall] [datetime] NULL 
) ON [PRIMARY]
end

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMEmpresas]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMEmpresas] (
 [Cuenta_Empresa] [int] NOT NULL ,
 [RutDV] [char] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
 [Estado_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Condicion_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Empresa] [char] (70) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Clasificacion_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [SucOper] [smallint] NULL ,
 [Actividad_Economica] [int] NULL 
) ON [PRIMARY]
end

 
if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMDR]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMDR] (
 [cuenta] [int] NOT NULL ,
 [Operacion] [int] NOT NULL ,
 [Total] [numeric](18, 0) NULL 
) ON [PRIMARY]
end

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMDP]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMDP] (
 [cuenta] [int] NOT NULL ,
 [Operacion] [int] NOT NULL ,
 [Total] [numeric](18, 0) NULL 
) ON [PRIMARY]
end

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMDETAFIL]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMDETAFIL] (
 [Cuenta_Empresa] [int] NULL ,
 [Nombre_Empresa] [char] (70) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta] [int] NULL ,
 [Operacion] [int] NULL ,
 [Nombre_Deudor] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Vcto_Impago] [datetime] NULL ,
 [Valor_Cuota] [numeric](18, 0) NULL 
) ON [PRIMARY]
end

 
if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMDETADESAFIL]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMDETADESAFIL] (
 [Cuenta_Empresa] [int] NULL ,
 [Nombre_Empresa] [char] (70) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta] [int] NULL ,
 [Operacion] [int] NULL ,
 [Nombre_Deudor] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Vcto_Impago] [datetime] NOT NULL ,
 [Valor_Cuota] [numeric](18, 0) NULL 
) ON [PRIMARY]
end

 
if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMCuentas]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMCuentas] (
 [Cuenta] [int] NOT NULL ,
 [Operacion] [int] NOT NULL 
) ON [PRIMARY]
end

 
if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMComercialDesafil]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[GMComercialDesafil] (
 [Cuenta_Empresa] [int] NULL ,
 [Nombre_Empresa] [char] (70) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Estado_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Condicion_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Clasificacion_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [SucOper] [smallint] NULL ,
 [Agencia] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [GERENTE] [varchar] (60) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [RC] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [RG] [decimal](20, 0) NULL ,
 [C_MANT] [decimal](20, 0) NULL ,
 [CI_MANT] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [EJECUTIVO_EMPRESAS] [varchar] (90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [SEGMENTO] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [CR] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [ESTADO] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [CONTRATO] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta] [int] NULL ,
 [Operacion] [int] NULL ,
 [Nombre_Deudor] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta_Aval1] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval1] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta_Aval2] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval2] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [MM60] [numeric](18, 0) NULL ,
 [DP] [numeric](18, 0) NULL ,
 [DR] [numeric](18, 0) NULL ,
 [Clasificacion] [char] (24) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Vcto_Impago] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Valor_Cuota] [numeric](18, 0) NULL 
) ON [PRIMARY]
end

 
if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMComercialAfil]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 begin
 CREATE TABLE [dbo].[GMComercialAfil] (
 [Cuenta_Empresa] [int] NULL ,
 [Nombre_Empresa] [char] (70) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Estado_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Condicion_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Clasificacion_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [SucOper] [smallint] NULL ,
 [Agencia] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [GERENTE] [varchar] (60) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [RC] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [RG] [decimal](20, 0) NULL ,
 [C_MANT] [decimal](20, 0) NULL ,
 [CI_MANT] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [EJECUTIVO_EMPRESAS] [varchar] (90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [SEGMENTO] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [CR] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [ESTADO] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [CONTRATO] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta] [int] NULL ,
 [Operacion] [int] NULL ,
 [Nombre_Deudor] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta_Aval1] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval1] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta_Aval2] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval2] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [MM60] [numeric](18, 0) NULL ,
 [DP] [numeric](18, 0) NULL ,
 [DR] [numeric](18, 0) NULL ,
 [Clasificacion] [char] (24) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Vcto_Impago] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Valor_Cuota] [numeric](18, 0) NULL 
) ON [PRIMARY]
end

 

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMBASEGESTCOMER]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 begin
 CREATE TABLE [dbo].[GMBASEGESTCOMER] (
 [Cuenta_Empresa] [int] NULL ,
 [Nombre_Empresa] [char] (70) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Estado_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Condicion_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Clasificacion_Empresa] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [SucOper] [smallint] NULL ,
 [Agencia] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [GERENTE] [varchar] (60) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [RC] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [RG] [decimal](20, 0) NULL ,
 [C_MANT] [decimal](20, 0) NULL ,
 [CI_MANT] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [EJECUTIVO_EMPRESAS] [varchar] (90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [SEGMENTO] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [CR] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [ESTADO] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [CONTRATO] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta] [int] NULL ,
 [Operacion] [int] NULL ,
 [Nombre_Deudor] [char] (35) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta_Aval1] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval1] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta_Aval2] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval2] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [MM60] [numeric](18, 0) NULL ,
 [DP] [numeric](18, 0) NULL ,
 [DR] [numeric](18, 0) NULL ,
 [Clasificacion] [char] (24) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Vcto_Impago] [datetime] NULL ,
 [Valor_Cuota] [numeric](18, 0) NULL 
) ON [PRIMARY]
end

 

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMBase]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 
 begin
  CREATE TABLE [GMBase] (
 [CTA_BT] [decimal](20, 0) NULL ,
 [RUT] [decimal](20, 0) NULL ,
 [DV] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [TRAB] [decimal](20, 0) NULL ,
 [SK] [decimal](20, 0) NULL ,
 [AGENCIA] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [GERENTE] [varchar] (60) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [RC] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [RG] [decimal](20, 0) NULL ,
 [C_MANT] [decimal](20, 0) NULL ,
 [CI_MANT] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [EJECUTIVO_EMPRESAS] [varchar] (90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [SEGMENTO] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [CR] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [ESTADO] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [CONTRATO] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [C_AG] [decimal](20, 0) NULL ,
 [RAZON_SOCIAL] [varchar] (107) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [FECHA_CREACION] [datetime] NULL 
) ON [PRIMARY]
 END
 

 

if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMJudiciales]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 
 Begin
  CREATE TABLE [dbo].[GMJudiciales] (
  [Cuenta_Empresa] [int] NULL ,
  [Cuenta] [int] NULL ,
  [Operacion] [int] NULL 
  ) ON [PRIMARY]
 end

 
 
 
if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMCtasEmpresas]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 
 begin
 CREATE TABLE [GMCtasEmpresas] (
 [Cuenta_Empresa] [int] NULL ,
 [cuenta] [int] NOT NULL ,
 [Operacion] [int] NOT NULL ,
 [Cuenta_Aval1] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval1] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Cuenta_Aval2] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
 [Nombre_Aval2] [varchar] (113) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
 END



if NOT exists (select * from dbo.sysobjects where id = object_id(N'[tmp_base]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 
 begin
 CREATE TABLE [dbo].[tmp_base] (
	[R1cta] [int] NULL ,
	[cuenta] [int] NOT NULL ,
	[Operacion] [int] NOT NULL ,
	[CODEUDOR1] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[CODEUDOR2] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
 END



if NOT exists (select * from dbo.sysobjects where id = object_id(N'[tmp_cod]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 
 begin
CREATE TABLE [dbo].[tmp_cod] (
	[cta] [int] NOT NULL ,
	[oper] [int] NOT NULL ,
	[suc] [smallint] NOT NULL ,
	[CODEUDOR1] [char] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[CODEUDOR2] [char] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
end


if NOT exists (select * from dbo.sysobjects where id = object_id(N'[GMFechaValorMO]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 
 begin
CREATE TABLE [dbo].[GMFechaValorMO] (
	[cuenta] [int] NOT NULL ,
	[operacion] [int] NOT NULL ,
	[fecha_venc] [datetime] NULL ,
	[monto] [decimal](38, 2) NULL 
) ON [PRIMARY]
end
GO

